package logic

import (
	"campus-trade/models/mysql"
	"context"

	"campus-trade/campusrpc/campusrpc"
	"campus-trade/campusrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentAddLogic) CommentAdd(in *campusrpc.CommentAddRequest) (*campusrpc.CommentAddResponse, error) {
	// todo: add your logic here and delete this line

	comment := mysql.Comment{
		UserId: in.UserId,
		BookId: in.BookId,
	}
	mysql.DB.Debug().Create(&comment)
	return &campusrpc.CommentAddResponse{
		CommentId: int64(comment.ID),
	}, nil
}
